home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Compilers⁄Interps / GCC-2.3.3r12 / Sources-Targets / vax-vms.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-05  |  13.0 KB  |  340 lines  |  [TEXT/MPS ]

  1. /* Output variables, constants and external declarations, for GNU compiler.
  2.    Copyright (C) 1988 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* This enables certain macros in vax.h, which will make an indirect
  21.    reference to an external symbol an invalid address.  This needs to be
  22.    defined before we include vax.h, since it determines which macros
  23.    are used for GO_IF_*.  */
  24.  
  25. #define NO_EXTERNAL_INDIRECT_ADDRESS
  26.  
  27. #include "vax.h"
  28.  
  29. #undef LIB_SPEC
  30. #undef CPP_PREDEFINES
  31. #undef TARGET_VERSION
  32. #undef TARGET_DEFAULT
  33. #undef CALL_USED_REGISTERS
  34. #undef MAYBE_VMS_FUNCTION_PROLOGUE
  35. #undef FUNCTION_PROLOGUE
  36. #undef STARTING_FRAME_OFFSET
  37.  
  38. /* Predefine this in CPP because VMS limits the size of command options
  39.    and GNU CPP is not used on VMS except with GNU C.  */
  40. #define CPP_PREDEFINES "-Dvax -Dvms -DVMS -D__GNUC__=2"
  41.  
  42. /* These match the definitions used in VAXCRTL, the VMS C run-time library */
  43.  
  44. #define SIZE_TYPE "unsigned int"
  45. #define PTRDIFF_TYPE "int"
  46. #define WCHAR_TYPE    "unsigned int"
  47.  
  48. /* Use memcpy for structure copying, and so forth.  */
  49. #define TARGET_MEM_FUNCTIONS
  50.  
  51. /* Strictly speaking, VMS does not use DBX at all, but the interpreter built
  52.    into gas only speaks straight DBX.  */
  53.  
  54. #define DEFAULT_GDB_EXTENSIONS 0
  55.  
  56. /* By default, allow $ to be part of an identifier.  */
  57. #define DOLLARS_IN_IDENTIFIERS 2
  58.  
  59. #define TARGET_DEFAULT 1
  60. #define TARGET_VERSION fprintf (stderr, " (vax vms)");
  61.  
  62. #define CALL_USED_REGISTERS {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1}
  63.  
  64. /* We redefine this because there is a hidden variable on the stack
  65.    that VAXC$ESTABLISH uses.  We just need to add four bytes to whatever
  66.    gcc thinks that we need.  Similarly, we need to move all local variables
  67.    down 4 bytes in the stack.  */
  68.  
  69. #define STARTING_FRAME_OFFSET -4
  70.  
  71. #define FUNCTION_PROLOGUE(FILE, SIZE)     \
  72. { register int regno;                        \
  73.   register int mask = 0;                    \
  74.   register int newsize = SIZE + 4;                \
  75.   extern char call_used_regs[];                    \
  76.   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)    \
  77.     if (regs_ever_live[regno] && !call_used_regs[regno])    \
  78.        mask |= 1 << regno;                    \
  79.   fprintf (FILE, "\t.word 0x%x\n", mask);            \
  80.   MAYBE_VMS_FUNCTION_PROLOGUE(FILE)                \
  81.   if (newsize >= 64) fprintf (FILE, "\tmovab %d(sp),sp\n", -newsize);\
  82.   else fprintf (FILE, "\tsubl2 $%d,sp\n", newsize); }
  83.  
  84. #define __MAIN_NAME " main ("
  85. /*
  86.  * The MAYBE_VMS_FUNCTION_PROLOGUE macro works for both gcc and g++.  It
  87.  * first checks to see if the current routine is "main", which will only
  88.  * happen for GCC, and add the jsb if it is.  If is not the case then try and 
  89.  * see if __MAIN_NAME is part of current_function_name, which will only happen
  90.  * if we are running g++, and add the jsb if it is.  In gcc there should never
  91.  * be a space in the function name, and in g++ there is always a "(" in the
  92.  * function name, thus there should never be any confusion.
  93.  */
  94. #define MAYBE_VMS_FUNCTION_PROLOGUE(FILE)    \
  95. { extern char *current_function_name;        \
  96.   if (!strcmp ("main", current_function_name))    \
  97.     fprintf(FILE, "\tjsb _C$MAIN_ARGS\n");     \
  98.   else {                    \
  99.     char *p = current_function_name;        \
  100.     while (*p != '\0')                \
  101.       if (*p == *__MAIN_NAME)            \
  102.         if (strncmp(p, __MAIN_NAME, (sizeof __MAIN_NAME)-1) == 0) {\
  103.           fprintf(FILE, "\tjsb _C$MAIN_ARGS\n");\
  104.           break;                \
  105.         } else                    \
  106.           p++;                    \
  107.       else                    \
  108.         p++;                    \
  109.      };                        \
  110. }
  111.  
  112. /* This macro definition sets up a default value for `main' to return.  */
  113. #define DEFAULT_MAIN_RETURN  c_expand_return (integer_one_node)
  114.  
  115. /* This makes use of a hook in varasm.c to mark all external variables
  116.    for us.  We use this to make sure that external variables are correctly
  117.    addressed.  Under VMS there is some brain damage in the linker that requires
  118.    us to do this.  */
  119.  
  120. #define ENCODE_SECTION_INFO(decl)                  \
  121.   if (DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))         \
  122.     SYMBOL_REF_FLAG (XEXP (DECL_RTL (decl), 0)) = 1; 
  123.  
  124. /* Under VMS we write the actual size of the storage to be allocated even
  125.    though the symbol is external.  Although it is possible to give external
  126.    symbols a size of 0 (as unix does), the VMS linker does not make the
  127.    distinction between a variable definition and an external reference of a
  128.    variable, and thus the linker will not complain about a missing definition.
  129.    If we followed the unix example of giving external symbols a size of
  130.    zero, you tried to link a program where a given variable was externally
  131.    defined but none of the object modules contained a non-extern definition,
  132.    the linker would allocate 0 bytes for the variable, and any attempt to
  133.    use that variable would use the storage allocated to some other variable.
  134.  
  135.    We must also select either const_section or data_section: this will indicate
  136.    whether or not the variable will get the readonly bit set.  Since the
  137.    VMS linker does not distinguish between a variable's definition and an
  138.    external reference, all usages of a given variable must have the readonly
  139.    bit set the same way, or the linker will get confused and give warning
  140.    messages.  */
  141.  
  142. /* We used to round the size up to a multiple of 4,
  143.    but that causes linker errors sometimes when the variable was initialized
  144.    since the size of its definition was not likewise rounded up.  */
  145.  
  146. #define ASM_OUTPUT_EXTERNAL(FILE,DECL,NAME)                \
  147. { if (DECL_INITIAL (DECL) == 0 && TREE_CODE (DECL) != FUNCTION_DECL)    \
  148.     {                                    \
  149.       if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl))        \
  150.     const_section ();                        \
  151.       else                                \
  152.     data_section ();                        \
  153.       fputs (".comm ", (FILE));                        \
  154.       assemble_name ((FILE), (NAME));                    \
  155.       if (DECL_SIZE (DECL) == 0)                    \
  156.         fprintf ((FILE), ",0\n");                    \
  157.       else                                \
  158.     {                                \
  159.       tree size_tree;                        \
  160.       size_tree = size_binop (CEIL_DIV_EXPR,            \
  161.          DECL_SIZE (DECL), size_int (BITS_PER_UNIT));        \
  162.       fprintf ((FILE), ",%d\n", TREE_INT_CST_LOW (size_tree));    \
  163.         }                                \
  164.     }                                    \
  165. }
  166.  
  167. /* Here we redefine ASM_OUTPUT_COMMON to select the data_section or the
  168.    const_section before writing the ".const" assembler directive.
  169.    If we were specifying a size of zero for external variables, we would
  170.    not have to select a section, since the assembler can assume that
  171.    when the size > 0, the storage is for a non-external, uninitialized
  172.    variable (for which a "const" declaration would be senseless),
  173.    and the assembler can make the storage read/write.
  174.  
  175.    Since the ".const" directive specifies the actual size of the storage used
  176.    for both external and non-external variables, the assembler cannot
  177.    make this assumption, and thus it has no way of deciding if storage should
  178.    be read/write or read-only.  To resolve this, we give the assembler some
  179.    assistance, in the form of a ".const" or a ".data" directive.
  180.  
  181.    Under GCC 1.40, external variables were declared with a size of zero.
  182.    The GNU assembler, GAS, will recognize the "-2" switch when built for VMS;
  183.    when compiling programs with GCC 2.n this switch should be used or the
  184.    assembler will not give the read-only attribute to external constants.
  185.    Failure to use this switch will result in linker warning messages about
  186.    mismatched psect attributes.  */
  187.  
  188. #undef ASM_OUTPUT_COMMON
  189.  
  190. #define ASM_OUTPUT_COMMON(FILE, NAME, SIZE, ROUNDED)        \
  191. ( ((TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl))    \
  192.    ? (const_section (), 0) : (data_section (), 0)),        \
  193.   fputs (".comm ", (FILE)),                    \
  194.   assemble_name ((FILE), (NAME)),                \
  195.   fprintf ((FILE), ",%u\n", (SIZE)))
  196.  
  197. /* We define this to prevent the name mangler from putting dollar signs into
  198.    function names.  This isn't really needed, but it has been here for
  199.    some time and  removing it would cause the object files generated by the
  200.    compiler to be incompatible with the object files from a compiler that
  201.    had this defined.  Since it does no harm, we leave it in.  */
  202.  
  203. #define NO_DOLLAR_IN_LABEL
  204.  
  205. /* Add a "const" section.  This is viewed by the assembler as being nearly
  206.    the same as the "data" section, with the only difference being that a
  207.    flag is set for variables declared while in the const section.  This
  208.    flag is used to determine whether or not the read/write bit should be
  209.    set in the Psect definition.  */
  210.  
  211. #define EXTRA_SECTIONS in_const
  212.  
  213. #define EXTRA_SECTION_FUNCTIONS                \
  214. void                            \
  215. const_section ()                    \
  216. {                            \
  217.   if (in_section != in_const) {                \
  218.     fprintf(asm_out_file,".const\n");            \
  219.     in_section = in_const;                \
  220.   }                            \
  221. }
  222.  
  223. /* This macro contains the logic to decide which section a variable
  224.    should be stored in.  Static constant variables go in the text_section,
  225.    non-const variables go in the data_section, and non-static const
  226.    variables go in the const_section.
  227.  
  228.    Since this macro is used in a number of places, we must also be able
  229.    to decide where to place string constants.  */
  230.  
  231. #define SELECT_SECTION(T,RELOC)                        \
  232. {                                    \
  233.   if (TREE_CODE (T) == VAR_DECL)                    \
  234.     {                                    \
  235.       if (TREE_READONLY (T) && ! TREE_THIS_VOLATILE (T))        \
  236.     {                                \
  237.       if (TREE_PUBLIC (T))                        \
  238.         const_section ();                        \
  239.       else                                \
  240.         text_section ();                        \
  241.     }                                \
  242.       else                                \
  243.     data_section ();                        \
  244.     }                                    \
  245.   if (*tree_code_type[(int) TREE_CODE (T)] == 'c')            \
  246.     {                                    \
  247.       if ((TREE_CODE (T) == STRING_CST && flag_writable_strings))    \
  248.     data_section ();                        \
  249.       else                                \
  250.     text_section ();                        \
  251.     }                                    \
  252. }
  253.  
  254. /* This is used by a hook in varasm.c to write the assembler directives
  255.    that are needed to tell the startup code which constructors need to
  256.    be run.  */
  257.  
  258. #define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME)                \
  259. {                                    \
  260.   fprintf ((FILE),".globl $$PsectAttributes_NOOVR$$__gxx_init_1\n");     \
  261.   data_section();                            \
  262.   fprintf ((FILE),"$$PsectAttributes_NOOVR$$__gxx_init_1:\n\t.long\t"); \
  263.   assemble_name ((FILE), (NAME));                    \
  264.   fputc ('\n', (FILE));                            \
  265. }
  266.  
  267. /* This is used by a hook in varasm.c to write the assembler directives
  268.    that are needed to tell the startup code which destructors need to
  269.    be run.  */
  270.  
  271. #define ASM_OUTPUT_DESTRUCTOR(FILE,NAME)                \
  272. {                                    \
  273.   fprintf ((FILE),".globl $$PsectAttributes_NOOVR$$__gxx_clean_1\n");     \
  274.   data_section();                            \
  275.   fprintf ((FILE),"$$PsectAttributes_NOOVR$$__gxx_clean_1:\n\t.long\t");\
  276.   assemble_name ((FILE), (NAME));                    \
  277.   fputc ('\n', (FILE));                            \
  278. }
  279.  
  280. /* The following definitions are used in libgcc2.c with the __main
  281.    function.  The _SHR symbol is used when the sharable image library
  282.    for libg++ is used - this is picked up automatically by the linker
  283.    and this symbol points to the start of the __CTOR_LIST__ from libg++.
  284.    If libg++ is not being used, then __CTOR_LIST_SHR__ occurs just after
  285.    __CTOR_LIST__, and essentially points to the same list as __CTOR_LIST.  */
  286.  
  287. #ifdef L__main
  288.  
  289. #define __CTOR_LIST__ __gxx_init_0
  290. #define __CTOR_LIST_END__ __gxx_init_2
  291.  
  292. #define __CTOR_LIST_SHR__ $$PsectAttributes_NOSHR$$__gxx_init_0_shr
  293. #define __CTOR_LIST_SHR_END__ $$PsectAttributes_NOSHR$$__gxx_init_2_shr
  294.  
  295. #define DO_GLOBAL_CTORS_BODY                        \
  296. do {                                    \
  297.   func_ptr *p;                                \
  298.   extern func_ptr __CTOR_LIST__[1];                    \
  299.   extern func_ptr __CTOR_LIST_END__[1];                    \
  300.   extern func_ptr __CTOR_LIST_SHR__[1];                    \
  301.   extern func_ptr __CTOR_LIST_SHR_END__[1];                \
  302.   if( &__CTOR_LIST_SHR__[0] != &__CTOR_LIST__[1])            \
  303.   for (p = __CTOR_LIST_SHR__ + 1; p < __CTOR_LIST_SHR_END__ ; p++ )    \
  304.     if (*p) (*p) ();                            \
  305.   for (p = __CTOR_LIST__ + 1; p < __CTOR_LIST_END__ ; p++ )        \
  306.     if (*p) (*p) ();                            \
  307.   atexit (__do_global_dtors);                        \
  308.     {                                    \
  309.       __label__ foo;                            \
  310.       int *callers_caller_fp = (int *) __builtin_frame_address (3);    \
  311.       register int retval asm ("r0");                    \
  312.       callers_caller_fp[4] = (int) && foo;                \
  313.       return;                                \
  314.     foo:                                \
  315.       exit (retval);                            \
  316.     }                                    \
  317. } while (0)
  318.  
  319. #define __DTOR_LIST__ __gxx_clean_0
  320. #define __DTOR_LIST_END__ __gxx_clean_2
  321.  
  322. #define __DTOR_LIST_SHR__ $$PsectAttributes_NOSHR$$__gxx_clean_0_shr
  323. #define __DTOR_LIST_SHR_END__ $$PsectAttributes_NOSHR$$__gxx_clean_2_shr
  324.  
  325. #define DO_GLOBAL_DTORS_BODY                        \
  326. do {                                    \
  327.   func_ptr *p;                                \
  328.   extern func_ptr __DTOR_LIST__[1];                    \
  329.   extern func_ptr __DTOR_LIST_END__[1];                    \
  330.   extern func_ptr __DTOR_LIST_SHR__[1];                    \
  331.   extern func_ptr __DTOR_LIST_SHR_END__[1];                \
  332.   for (p = __DTOR_LIST__ + 1; p < __DTOR_LIST_END__ ; p++ )        \
  333.     if (*p) (*p) ();                            \
  334.   if( &__DTOR_LIST_SHR__[0] != &__DTOR_LIST__[1])            \
  335.   for (p = __DTOR_LIST_SHR__ + 1; p < __DTOR_LIST_SHR_END__ ; p++ )    \
  336.     if (*p) (*p) ();                            \
  337. } while (0)
  338.  
  339. #endif /* L__main */
  340.